package com.zshan.clinic.cms.controller.config;


import com.zshan.clinic.admin.entity.vo.DictAcupointTreeVo;
import com.zshan.clinic.admin.entity.vo.DictRegionTreeVo;
import com.zshan.clinic.admin.service.config.ClinicDictService;
import com.zshan.clinic.cms.common.core.controller.BaseController;
import com.zshan.clinic.cms.common.core.domain.AjaxResult;
import com.zshan.clinic.cms.common.core.domain.entity.SysUser;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.database.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 诊所信息
 */
@RestController
@RequestMapping("/config/dict")
public class ClinicDictController extends BaseController {


    @Autowired
    private ClinicDictService clinicDictService;

    /**
     * 获取区域列表
     * @return
     */
    @GetMapping("/getRegionTreeList")
    public AjaxResult getRegionTreeList(){
        List<DictRegionTreeVo> regionTreeList = clinicDictService.getRegionTreeList();
        return AjaxResult.success(regionTreeList);
    }

    /**
     * 查询系统字典列表
     * @param dictCode 字典编码
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/geDictSysListByCondition")
    public AjaxResult geDictSysListByCondition(@RequestParam(name = "dictCode",required = false) String dictCode,
                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        PageInfo<DictSys> pageInfo = clinicDictService.geDictSysListByCondition(dictCode,pageNo,pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加字典
     * @param dictSys
     * @return
     */
    @PostMapping("/addDict")
    public AjaxResult addDict(@RequestBody DictSys dictSys) {
        SysUser sysUser = getUser();
        dictSys.setCreateUserId(sysUser.getUserId());
        dictSys.setCreateBy(sysUser.getUserName());
        clinicDictService.addDict(dictSys);
        return AjaxResult.success();
    }

    /**
     * 修改字典
     * @param dictSys
     * @return
     */
    @PostMapping("/updateDict")
    public AjaxResult updateDict(@RequestBody DictSys dictSys) {
        SysUser sysUser = getUser();
        dictSys.setUpdateUserId(sysUser.getUserId());
        dictSys.setUpdateBy(sysUser.getUserName());
        clinicDictService.updateDict(dictSys);
        return AjaxResult.success();
    }

    /**
     * 删除字典
     * @param dictSys
     * @return
     */
    @PostMapping("/deleteDict")
    public AjaxResult deleteDict(@RequestBody DictSys dictSys) {
        SysUser sysUser = getUser();
        dictSys.setUpdateUserId(sysUser.getUserId());
        dictSys.setUpdateBy(sysUser.getUserName());
        clinicDictService.deleteDict(dictSys);
        return AjaxResult.success();
    }


    /**
     * 查询系统字典值列表
     * @param dictCode 字典编码
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/geDictItemListByCondition")
    public AjaxResult geDictItemListByCondition(@RequestParam(name = "dictCode",required = false) String dictCode,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        PageInfo<DictSysItem> pageInfo = clinicDictService.geDictItemListByCondition(dictCode,pageNo,pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加字典值
     * @param dictSysItem
     * @return
     */
    @PostMapping("/addItem")
    public AjaxResult addItem(@RequestBody DictSysItem dictSysItem) {
        SysUser sysUser = getUser();
        dictSysItem.setCreateUserId(sysUser.getUserId());
        dictSysItem.setCreateBy(sysUser.getUserName());
        clinicDictService.addItem(dictSysItem);
        return AjaxResult.success();
    }

    /**
     * 修改字典值
     * @param dictSysItem
     * @return
     */
    @PostMapping("/updateItem")
    public AjaxResult updateItem(@RequestBody DictSysItem dictSysItem) {
        SysUser sysUser = getUser();
        dictSysItem.setUpdateUserId(sysUser.getUserId());
        dictSysItem.setUpdateBy(sysUser.getUserName());
        clinicDictService.updateItem(dictSysItem);
        return AjaxResult.success();
    }

    /**
     * 删除字典值
     * @param dictSysItem
     * @return
     */
    @PostMapping("/deleteItem")
    public AjaxResult deleteItem(@RequestBody DictSysItem dictSysItem) {
        SysUser sysUser = getUser();
        dictSysItem.setUpdateUserId(sysUser.getUserId());
        dictSysItem.setUpdateBy(sysUser.getUserName());
        clinicDictService.deleteItem(dictSysItem);
        return AjaxResult.success();
    }


    /**
     * 查询频率列表
     * @param frequencyName 频率名
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getFrequencyListByCondition")
    public AjaxResult getFrequencyListByCondition(@RequestParam(name = "frequencyName",required = false) String frequencyName,
                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        PageInfo<DictFrequency> pageInfo = clinicDictService.getFrequencyListByCondition(frequencyName,pageNo,pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加频率
     * @param dictFrequency
     * @return
     */
    @PostMapping("/addFrequency")
    public AjaxResult addFrequency(@RequestBody DictFrequency dictFrequency) {
        SysUser sysUser = getUser();
        dictFrequency.setCreateUserId(sysUser.getUserId());
        dictFrequency.setCreateBy(sysUser.getUserName());
        clinicDictService.addFrequency(dictFrequency);
        return AjaxResult.success();
    }

    /**
     * 修改频率
     * @param dictFrequency
     * @return
     */
    @PostMapping("/updateFrequency")
    public AjaxResult updateFrequency(@RequestBody DictFrequency dictFrequency) {
        SysUser sysUser = getUser();
        dictFrequency.setUpdateUserId(sysUser.getUserId());
        dictFrequency.setUpdateBy(sysUser.getUserName());
        clinicDictService.updateFrequency(dictFrequency);
        return AjaxResult.success();
    }

    /**
     * 删除频率
     * @param dictFrequency
     * @return
     */
    @PostMapping("/deleteFrequency")
    public AjaxResult deleteFrequency(@RequestBody DictFrequency dictFrequency) {
        SysUser sysUser = getUser();
        dictFrequency.setUpdateUserId(sysUser.getUserId());
        dictFrequency.setUpdateBy(sysUser.getUserName());
        clinicDictService.deleteFrequency(dictFrequency);
        return AjaxResult.success();
    }

    /**
     * 查询服用方式列表
     * @param usageName 服用方式名
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getUsageListByCondition")
    public AjaxResult getUsageListByCondition(@RequestParam(name = "usageName", required = false) String usageName,
                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<DictUsage> pageInfo = clinicDictService.getUsageListByCondition(usageName, pageNo, pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加服用方式
     * @param dictUsage
     * @return
     */
    @PostMapping("/addUsage")
    public AjaxResult addUsage(@RequestBody DictUsage dictUsage) {
        SysUser sysUser = getUser();
        dictUsage.setCreateUserId(sysUser.getUserId());
        dictUsage.setCreateBy(sysUser.getUserName());
        clinicDictService.addUsage(dictUsage);
        return AjaxResult.success();
    }

    /**
     * 修改服用方式
     * @param dictUsage
     * @return
     */
    @PostMapping("/updateUsage")
    public AjaxResult updateUsage(@RequestBody DictUsage dictUsage) {
        SysUser sysUser = getUser();
        dictUsage.setUpdateUserId(sysUser.getUserId());
        dictUsage.setUpdateBy(sysUser.getUserName());
        clinicDictService.updateUsage(dictUsage);
        return AjaxResult.success();
    }

    /**
     * 删除服用方式
     * @param dictUsage
     * @return
     */
    @PostMapping("/deleteUsage")
    public AjaxResult deleteUsage(@RequestBody DictUsage dictUsage) {
        SysUser sysUser = getUser();
        dictUsage.setUpdateUserId(sysUser.getUserId());
        dictUsage.setUpdateBy(sysUser.getUserName());
        clinicDictService.deleteUsage(dictUsage);
        return AjaxResult.success();
    }



    /**
     * 查询处方备注列表
     * @param remarkName 处方备注名
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getRemarkListByCondition")
    public AjaxResult getRemarkListByCondition(@RequestParam(name = "remarkName", required = false) String remarkName,
                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<DictRemark> pageInfo = clinicDictService.getRemarkListByCondition(remarkName, pageNo, pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加处方备注
     * @param dictRemark
     * @return
     */
    @PostMapping("/addRemark")
    public AjaxResult addRemark(@RequestBody DictRemark dictRemark) {
        SysUser sysUser = getUser();
        dictRemark.setCreateUserId(sysUser.getUserId());
        dictRemark.setCreateBy(sysUser.getUserName());
        clinicDictService.addRemark(dictRemark);
        return AjaxResult.success();
    }

    /**
     * 修改处方备注
     * @param dictRemark
     * @return
     */
    @PostMapping("/updateRemark")
    public AjaxResult updateRemark(@RequestBody DictRemark dictRemark) {
        SysUser sysUser = getUser();
        dictRemark.setUpdateUserId(sysUser.getUserId());
        dictRemark.setUpdateBy(sysUser.getUserName());
        clinicDictService.updateRemark(dictRemark);
        return AjaxResult.success();
    }

    /**
     * 删除处方备注
     * @param dictRemark
     * @return
     */
    @PostMapping("/deleteRemark")
    public AjaxResult deleteRemark(@RequestBody DictRemark dictRemark) {
        SysUser sysUser = getUser();
        dictRemark.setUpdateUserId(sysUser.getUserId());
        dictRemark.setUpdateBy(sysUser.getUserName());
        clinicDictService.deleteRemark(dictRemark);
        return AjaxResult.success();
    }

    /**
     * 查询用量单位列表
     * @param unitName 用量单位名
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getUnitListByCondition")
    public AjaxResult getUnitListByCondition(@RequestParam(name = "unitName", required = false) String unitName,
                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<DictUnit> pageInfo = clinicDictService.getUnitListByCondition(unitName, pageNo, pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加用量单位
     * @param dictUnit
     * @return
     */
    @PostMapping("/addUnit")
    public AjaxResult addUnit(@RequestBody DictUnit dictUnit) {
        SysUser sysUser = getUser();
        dictUnit.setCreateUserId(sysUser.getUserId());
        dictUnit.setCreateBy(sysUser.getUserName());
        clinicDictService.addUnit(dictUnit);
        return AjaxResult.success();
    }

    /**
     * 修改用量单位
     * @param dictUnit
     * @return
     */
    @PostMapping("/updateUnit")
    public AjaxResult updateUnit(@RequestBody DictUnit dictUnit) {
        SysUser sysUser = getUser();
        dictUnit.setUpdateUserId(sysUser.getUserId());
        dictUnit.setUpdateBy(sysUser.getUserName());
        clinicDictService.updateUnit(dictUnit);
        return AjaxResult.success();
    }

    /**
     * 删除用量单位
     * @param dictUnit
     * @return
     */
    @PostMapping("/deleteUnit")
    public AjaxResult deleteUnit(@RequestBody DictUnit dictUnit) {
        SysUser sysUser = getUser();
        dictUnit.setUpdateUserId(sysUser.getUserId());
        dictUnit.setUpdateBy(sysUser.getUserName());
        clinicDictService.deleteUnit(dictUnit);
        return AjaxResult.success();
    }


    /**
     * 查询穴位列表
     * @param acupointText 穴位名
     * @return
     */
    @GetMapping("/getAcupointTreeList")
    public AjaxResult getAcupointTreeList(@RequestParam(name = "acupointText", required = false) String acupointText) {
        List<DictAcupointTreeVo> treeList = clinicDictService.getAcupointTreeList(acupointText);
        return AjaxResult.success(treeList);
    }

    /**
     * 添加穴位
     * @param dictAcupoint
     * @return
     */
    @PostMapping("/addAcupoint")
    public AjaxResult addAcupoint(@RequestBody DictAcupoint dictAcupoint) {
        SysUser sysUser = getUser();
        dictAcupoint.setCreateUserId(sysUser.getUserId());
        dictAcupoint.setCreateBy(sysUser.getUserName());
        clinicDictService.addAcupoint(dictAcupoint);
        return AjaxResult.success();
    }

    /**
     * 修改穴位
     * @param dictAcupoint
     * @return
     */
    @PostMapping("/updateAcupoint")
    public AjaxResult updateAcupoint(@RequestBody DictAcupoint dictAcupoint) {
        SysUser sysUser = getUser();
        dictAcupoint.setUpdateUserId(sysUser.getUserId());
        dictAcupoint.setUpdateBy(sysUser.getUserName());
        clinicDictService.updateAcupoint(dictAcupoint);
        return AjaxResult.success();
    }

    /**
     * 删除穴位
     * @param dictAcupoint
     * @return
     */
    @PostMapping("/deleteAcupoint")
    public AjaxResult deleteAcupoint(@RequestBody DictAcupoint dictAcupoint) {
        SysUser sysUser = getUser();
        dictAcupoint.setUpdateUserId(sysUser.getUserId());
        dictAcupoint.setUpdateBy(sysUser.getUserName());
        clinicDictService.deleteAcupoint(dictAcupoint);
        return AjaxResult.success();
    }

}
